#import "MBProgressHUD+Add.h"
@implementation MBProgressHUD (Add)
+ (MBProgressHUD*)showSuccess:(NSString *)success
{
    return [self showSuccess:success toView:nil];
}

+ (MBProgressHUD*)showError:(NSString *)error
{
   return [self showError:error toView:nil];
}

+ (MBProgressHUD*)showInfo:(NSString *)info
{
    return [self showInfo:info toView:nil];
}

+ (MBProgressHUD*)showtext:(NSString *)text
{
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:kAppWindow animated:YES];
    hud.mode = MBProgressHUDModeText;
    hud.label.text = text;
    hud.label.numberOfLines = 0;
    hud.label.textColor = UIColor.whiteColor;
    // Move to bottm center.
    hud.offset = CGPointMake(0.f, MBProgressMaxOffset);
    //放置图片和文字的view,设置了蒙版就使用不了背景颜色
//    hud.bezelView.blurEffectStyle = UIBlurEffectStyleDark;
    //不使用蒙版,使用背景颜色
    hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
    hud.bezelView.backgroundColor = kColorRGBA(0, 0, 0,  0.8);
    [hud hideAnimated:YES afterDelay:1.5];
    return hud;
}
+ (MBProgressHUD*)showDefaultLoadingMessage:(NSString *)text
{
    return [self showMessage:text view:nil];
}
+ (MBProgressHUD*)showDefaultLoadingMessage:(NSString *)text toView:(UIView *)view
{
   return [self showMessage:text view:view];
}

/**显示自定义加载样式到window*/
+ (MBProgressHUD *)showCustomLoadingMessage:(NSString *)text
{
    
        MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:kAppWindow animated:YES];
        hud.label.text = text;
        UIImageView *customImg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"MBProgressHUD.bundle/%@", @"loading_b"]]];
        CABasicAnimation *anima = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
        anima.toValue = @(M_PI*2);
        anima.duration = 1.0f;
        anima.repeatCount = 10000;
        [customImg.layer addAnimation:anima forKey:nil];
    
        hud.customView = customImg;
        hud.mode = MBProgressHUDModeCustomView;
        //放置图片和文字的view,设置了蒙版就使用不了背景颜色
    //    hud.bezelView.blurEffectStyle = UIBlurEffectStyleDark;
        //不使用蒙版,使用背景颜色
        hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
        hud.bezelView.backgroundColor = kColorRGBA(0, 0, 0,  0.8);
        //图片和文字的颜色
        hud.contentColor = [UIColor whiteColor];
        hud.removeFromSuperViewOnHide = YES;
        return hud;
}
+(MBProgressHUD*)showProgress:(NSString*)text
{
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:kAppWindow animated:YES];
    hud.label.text = text;
    hud.label.numberOfLines = 0;
    hud.mode = MBProgressHUDModeDeterminateHorizontalBar;
    //放置图片和文字的view,设置了蒙版就使用不了背景颜色
    //    hud.bezelView.blurEffectStyle = UIBlurEffectStyleDark;
    //不使用蒙版,使用背景颜色
    hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
    hud.bezelView.backgroundColor = kColorRGBA(0, 0, 0,  0.8);
    //图片和文字的颜色
    hud.contentColor = [UIColor whiteColor];
    hud.removeFromSuperViewOnHide = YES;
    return hud;
}


+ (MBProgressHUD*)show:(NSString *)text icon:(NSString *)icon view:(UIView *)view
{
    if (view == nil) view = [UIApplication sharedApplication].keyWindow;
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.label.text = text;
    hud.label.numberOfLines = 0;
    hud.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[NSString stringWithFormat:@"MBProgressHUD.bundle/%@", icon]]];
    hud.mode = MBProgressHUDModeCustomView;
    //放置图片和文字的view,设置了蒙版就使用不了背景颜色
//    hud.bezelView.blurEffectStyle = UIBlurEffectStyleDark;
    //不使用蒙版,使用背景颜色
    hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
    hud.bezelView.backgroundColor = kColorRGBA(0, 0, 0,  0.8);
    //图片和文字的颜色
    hud.contentColor = [UIColor whiteColor];
    hud.removeFromSuperViewOnHide = YES;
    [hud hideAnimated:YES afterDelay:1.5];
    return hud;
}

+ (MBProgressHUD*)showError:(NSString *)error toView:(UIView *)view{
   return [self show:error icon:@"error.png" view:view];
}

+ (MBProgressHUD*)showSuccess:(NSString *)success toView:(UIView *)view
{
    return [self show:success icon:@"success.png" view:view];
}

+ (MBProgressHUD*)showInfo:(NSString *)success toView:(UIView *)view
{
    return [self show:success icon:@"info.png" view:view];
}

+ (MBProgressHUD*)showMessage:(NSString *)text view:(UIView *)view
{
    if (view == nil) view = [UIApplication sharedApplication].keyWindow;
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.label.text = text;
    hud.mode = MBProgressHUDModeIndeterminate;
    //放置图片和文字的view,设置了蒙版就使用不了背景颜色
    //    hud.bezelView.blurEffectStyle = UIBlurEffectStyleDark;
    //不使用蒙版,使用背景颜色
    hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
    hud.bezelView.backgroundColor = kColorRGBA(0, 0, 0,  0.8);
    //图片和文字的颜色
    hud.contentColor = [UIColor whiteColor];
    hud.removeFromSuperViewOnHide = YES;
    return hud;
}


+ (MBProgressHUD *)showMessage:(NSString *)message toView:(UIView *)view {
    if (view == nil) view = [UIApplication sharedApplication].keyWindow;
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.label.text = message;
    //放置图片和文字的view,设置了蒙版就使用不了背景颜色
    //    hud.bezelView.blurEffectStyle = UIBlurEffectStyleDark;
        //不使用蒙版,使用背景颜色
        hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;
        hud.bezelView.backgroundColor = kColorRGBA(0, 0, 0,  0.8);
        //图片和文字的颜色
        hud.contentColor = [UIColor whiteColor];
    hud.removeFromSuperViewOnHide = YES;
   
    return hud;
}

+(void)dismiss{
    [MBProgressHUD hideHUDForView:[UIApplication sharedApplication].keyWindow animated:YES];
}

@end
